package org.activemonitoring.datastore.rest;

import javax.annotation.Resource;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;

import org.activemonitoring.datastore.DataStore;
import org.activemonitoring.datastore.dao.DataStoreDao;
import org.activemonitoring.domain.Measures;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Configurable;

@Path("datastore")
@Configurable
public class DataStoreRestResource implements DataStore {

    private static final Logger logger = Logger.getLogger(DataStoreRestResource.class);

    @Resource
    private DataStoreDao dataStoreDao;

    @POST
    @Path("")
    @Consumes("text/xml")
    public void store(Measures measures) {
        if (logger.isInfoEnabled()) {
            logger.info("Received " + measures.getMeasure().size() + " measures");
        }
        this.dataStoreDao.store(measures);
    }

    @GET
    @Path("ping")
    @Produces("text/plain")
    public String ping() {
        return "pinged!";
    }

    public void setDataStoreDao(DataStoreDao dataStoreDao) {
        this.dataStoreDao = dataStoreDao;
    }

}
